const util = require('../../utils/util.js')
Page({
  data:{
    serie : '',
    serieId : '',
    category : '',
    years: []
  },
  onLoad(option){
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    this.setData({
      serie: option.serie,
      serieId: option.id,
      category : option.category
    })
    var that = this;
    wx.request({
      url: util.http+"years/",
      data:{
        series: that.data.serieId,
        category : that.data.category
      },
      header: {
        'content-type': 'application/json'
      },
      success : function(res){
        console.log(res.data)
        that.setData({
          years : res.data
        })
      },
      complete : function(res){
        wx.hideLoading();
        console.log(res)
        if (res == null || res.data == []) {
          console.error('网络请求失败');
        }
      }
    })
  },
  /*intYear : function(data){
    var years = [];
    for (var i=0;i<data.length;i++){
      var getYear = data[i][0] == data[i][1] ? data[i][0] : data[i][0] + "-" + data[i][1];
      years.push(getYear)
    }
    this.setData({
      years : years
    })
  }, */
  clickYear(e){
    var startYear = e.target.dataset.startyear,
        endYear = e.target.dataset.endyear,
        serieId = this.data.serieId,
        category = this.data.category;
    var link = '../cargo/cargo?startYear='+startYear+'&endYear='+endYear+'&serie='+serieId+'&category='+category;
    wx.navigateTo({
      url: link
    })
  }
})